<?php


namespace Swb\Shop\Helper;


use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Database\Model\Builder;
use swb\shop\Model\SysDataDict;
use Hyperf\DbConnection\Db;
use swb\shop\Model\SysUser;
use swb\shop\Model\TBuilding;
use swb\shop\Model\TBuildingDictionary;
use swb\shop\Model\THouseDictionary;
use swb\shop\Model\TProject;
use swb\shop\Model\TShop;
use Swb\Shop\Model\TShopReport;

trait ShopTrait
{
	public function get_logo(string $id)
	{
		return Db::table('t_professional_work_file as tw')->leftJoin('sys_file as sf', 'sf.id', '=', 'tw.file_id')->where('professional_work_id', $id)->where('logo_status', 1)->value('access_path');

	}
	public function get_building(string $buildId, $filed='*')
	{
		return TBuilding::query()->where('id', $buildId)->select($filed)->first();
	}

	/**
	 * @param $shop
	 * @param $build
	 * @param $house_id
	 * @return mixed
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * @todo  去除 view_history  my_like
	 * 大咖说铺后面更新,先做临时处理
	 */
	protected function get_rent_house($shop, $build, $house_id)
	{
		try{
			$shop_file                          =$this->get_shop_file($house_id);
			$basic_info['shop_file']['video']   =$shop_file[3103]??[];
			$basic_info['shop_file']['images']  =$shop_file[3102]??[];
			$basic_info['shop_file']['room_pic']=$shop_file[3101]??[];
			$basic_info['shop_file']['num']     =count($basic_info['shop_file']['images'])+count($basic_info['shop_file']['room_pic']);
			$basic_info['name']                 =$shop['name'];
			$basic_info['price']                =$shop['rental_price'];
			$basic_info['area']                 =$shop['floor_area'];
			$basic_info['shop_require']         =$shop['shop_require']?$this->get_dict($shop['shop_require']) : '';
			//转让费
//			if($shop['is_transfer']==1){
//				$basic_info['assignment_fee']=$shop['is_discuss_personally']==1?'面议': $shop['assignment_fee'].'万';
//			}else{
//				$basic_info['assignment_fee'] = '';
//			}
			$basic_info['assignment_fee'] =  $shop['assignment_fee']?$shop['assignment_fee'].'万':'无';
			//目前业态
			$basic_info['now_status']=$shop['now_status'] ?: '';
			//营业状态
			$basic_info['operating_state']=$shop['operating_state'] ? config('swb_shop.shop_operate_state')[$shop['operating_state']] : '';
			//新旧状态
			$basic_info['degree_new_old']=$shop['degree_new_old'] ? $this->get_dict($shop['degree_new_old']) : '';
			//商铺介绍
			$basic_info['house_describe']=$shop['house_describe'] ?: '';

			//业主电话
			$basic_info['build']['address']  =$build['building_address'];
			$basic_info['build']['longitude']=$build['longitude'];
			$basic_info['build']['latitude'] =$build['latitude'];
			//图片资源
			$basic_info['video_group'] = $this->get_shop_all_video($house_id,1);

			$basic_info['build']['yetai']    =bxy_array_by_group($this->get_house_dictionary($shop['id']), 'type')[2]??[];
			$shop_map                        =$this->get_map();
			foreach ($shop_map as $key=>$item){
				$basic_info['shop_des'][$key]['key']=$item['title'];
				if ($item['is_dict']===1){
					$basic_info['shop_des'][$key]['value']=$shop[$item['key']] ? $this->get_dict($shop[$item['key']]).$item['d'] : '';
				}else{
					$basic_info['shop_des'][$key]['value']=$shop[$item['key']].$item['d'];
				}

			}
			$basic_info['sheshi']=$this->shop_peitao($shop['id']);
			$basic_info['label'] =bxy_array_by_group($this->get_house_dictionary($shop['id']), 'type')[3]??[];
			$basic_info['agent'] =$shop['agent_id'] ? $this->get_agent($shop['agent_id']) : new \stdClass();
			$basic_info['shop_group_pic']                    =$this->more_pic();
			//周边业态
			$basic_info['total']  =bcmul($shop['rental_price'], $shop['floor_area']);
			return $basic_info;
		}catch (\Throwable $e){

		}
	}
	protected function get_shop_file($id): array
	{
		$info=Db::table('t_professional_work_file as a')
			->join('sys_file as b', 'a.file_id', '=', 'b.id')->where('professional_work_id', $id)
			->select('b.access_path', 'a.file_type','a.logo_status')
			->orderBy('logo_status')
			->get();
		$info=$info ? bxy_array_by_group($info, 'file_type') : [];
		return $info;
	}
	protected function get_dict($id)
	{
		return SysDataDict::query()->where('id', $id)->value('name');
	}
	protected function get_house_dictionary(string $house_id)
	{
		//2适合业态 3标签
		$info=THouseDictionary::query()->select('id', 'type', 'dictionaries_name')->where('house_id', $house_id)->whereIn('type', [2, 3])->get();
		return $info ?: [];

	}
	/**
	 * @return array
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 *
	 */
	protected function get_map(): array
	{
		return  [['title'=>'楼层', 'd'=>'', 'key'=>'floor_number_name', 'is_dict'=>0], ['title'=>'层高', 'd'=>'m', 'key'=>'shop_height', 'is_dict'=>0], ['title'=>'进深', 'd'=>'m', 'key'=>'shop_depth', 'is_dict'=>0], ['title'=>'面宽', 'd'=>'m', 'key'=>'shop_wide', 'is_dict'=>0], ['title'=>'装修状态', 'd'=>'', 'is_dict'=>1, 'key'=>'renovation_type'], ['title'=>'合同期', 'd'=>'', 'is_dict'=>1, 'key'=>'contract_term'], ['title'=>'免租期', 'd'=>'', 'is_dict'=>1, 'key'=>'rent_free_period'], ['title'=>'押金', 'd'=>'', 'is_dict'=>1, 'key'=>'cash_pledge'], ['title'=>'一次付租周期', 'd'=>'', 'is_dict'=>1, 'key'=>'rent_to_pay_cycle'], ['title'=>'是否临街', 'd'=>'', 'is_dict'=>1, 'key'=>'is_street'], ['title'=>'商铺类型', 'd'=>'', 'is_dict'=>1, 'key'=>'shop_type'],];
	}
	protected function shop_peitao(string $house_id)
	{

		$info=THouseDictionary::query()->leftJoin('sys_file as sf', 'sf.id', '=', 't_house_dictionaries.icon')->select('t_house_dictionaries.id', 't_house_dictionaries.type', 't_house_dictionaries.dictionaries_name', 'sf.access_path')->where('t_house_dictionaries.house_id', $house_id)->where('t_house_dictionaries.type', 1)->get();
		return $info ?: [];
	}
	/**
	 * @return array
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 多图
	 */
	protected function more_pic(): array
	{
		$arr=[];
		$map=['客流分析', '周边业态', '周边交通'];
//		for ($i=0; $i<3; $i++){
//			$arr[$i]['title']    =$map[$i];
//			$arr[$i]['cover_pic']='https://swb-bucket01.oss-cn-zhangjiakou.aliyuncs.com/swb/test/picture/202003141953591584186839964.png';
//			$arr[$i]['image']    ='https://swb-bucket01.oss-cn-zhangjiakou.aliyuncs.com/swb/test/picture/202003141953591584186839964.png';
//		}
		return $arr;
	}
	/**
	 * @param $agent_id
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 经济人网店
	 * @todo 经纪人抽离成composer包
	 * @return Builder|\Hyperf\Database\Model\Model|\Hyperf\Database\Query\Builder|object|null
	 */
	protected function get_agent($agent_id)
	{
		$data=SysUser::query()->where('sys_user.id', $agent_id)->leftJoin('sys_file as sf', 'sf.id', '=', 'sys_user.head_pic')->select('phone', 'user_name', 'sf.access_path', 'good_business', 'sys_user.id','department_name')->first();
		if ($data){
			$data['tag']=['服务之星', '资深顾问', '投资专家'];
		}
		return $data ?: new \stdClass();
	}
	protected function get_daka()
	{
		$arr['video_pic'] = '';
		return $arr;
	}
	protected function get_people()
	{
		$arr['video_pic'] = '';
		return $arr;
	}
	protected function get_project_price($project_id,$type=2)
	{
		$house_sale_rent = $type==2?1:2;
		$avg=TShop::query()->where('project_id', $project_id)
			->where('del_flag', 1)
			->where('house_sale_rent', $house_sale_rent)
			->selectRaw('avg(rental_price) as avg_rental_price,avg(sale_price) as avg_price,avg(floor_area) as avg_area,min(floor_area) as min_area,max(floor_area) as max_area')
			->first();

		if($type==2){
			$avg_price = $avg['avg_rental_price']?ceil($avg['avg_rental_price']):0;
			if ($avg['avg_area']&& $avg_price)
			{
				$avg_total=ceil($avg['avg_area']*$avg_price);
			}
		}
		if($type==3){
			$avg_price = $avg['avg_price']?ceil($avg['avg_price']):0;
			if ($avg['avg_area']&&$avg_price){
				$avg_total=ceil($avg['avg_area']*$avg_price);
			}
		}
		return ['avg_price'=>$avg_price??0, 'avg_total'=>$avg_total??0, 'min_area'=>$avg['min_area'] ?: 0, 'max_area'=>$avg['max_area']?:0,'avg_area'=>$avg['avg_area']?:0];

	}

	/**
	 * @param $project_id
	 * @param $type
	 * @return mixed
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * @todo goods_agent  view_history  agent  my_like
	 */
	protected function get_sell_new_shop($project_id,$type)
	{
		$project  =$this->get_project($project_id);
		$build    =$this->get_building($project['building_id']);
		$avg_price=$this->get_project_price($project_id,$type);
		$basic_info['ready_open_time']=$project['ready_open_time']?:'';
		//目前状态
		$basic_info['formats']=$project['formats'] ? $this->get_dict($project['formats']) : '';
		$basic_info['in_shop']=$project['in_shop'] ?: 0;// 已进商家
		if($type==2)
		{
			$rent_shop_num=TShop::query()
				->where('project_id', $project_id)
				->where('del_flag',1)
				->where('house_sale_rent', 1)
				->whereIn('house_status', [1,2,3,5])
				->count();
		}else{
			$rent_shop_num=TShop::query()
				->where('project_id', $project_id)
				->where('house_sale_rent', 2)
				->whereIn('house_status', [1,2,5,8])
				->where('del_flag',1)
				->count();
		}
		$basic_info['rent_shop_num'] = $rent_shop_num?:0;
		//@todo 项目评测
		if ($project['introduce']){
			$project_remark_img = bxy_get_content_img($project['introduce']);
			$basic_info['project_remark']['cover_pic']=$project_remark_img?$project_remark_img:'';
			$basic_info['project_remark']['des']      =preg_replace("/(\s|\&nbsp\;|　|\xc2\xa0)/",'',strip_tags($project['introduce']));
			$basic_info['project_remark']['content']  =$project['introduce'];
		}else{
			$basic_info['project_remark']=new \stdClass();
		}
		$shop_file                                       =$this->get_shop_file($project_id);
		$basic_info['shop_file']['video']                =$shop_file[2105]??[];
		$basic_info['shop_file']['images']               =$shop_file[2102]??[];
		$basic_info['shop_file']['room_pic']             =$shop_file[2101]??[];
		$basic_info['shop_file']['num']                  =count($basic_info['shop_file']['images'])+count($basic_info['shop_file']['room_pic']);
		$basic_info['sheshi']                            =$this->project_tag($project_id);
		$basic_info['shop_list']                         =$this->shop_list($project_id,$type);
		$basic_info['brand_group']                       =$this->get_project_brand($project_id);
		$basic_info['project_news']                      =$this->get_project_info($project_id);
		$basic_info['name']                              =$build['building_name'];
		$basic_info['label']                             =$this->get_building_dictionary($build['id'], 1);
		$basic_info['price']                             =$type==2?$avg_price['avg_price']:number_format($avg_price['avg_price']/10000,2,'.','');
		$basic_info['total']                             =$type==2?$avg_price['avg_total']:number_format($avg_price['avg_total']/10000,2,'.','');
		$basic_info['area']                              =$avg_price['min_area'].'-'.$avg_price['max_area'];
		$basic_info['video_group']                       = $this->get_shop_all_video($project_id,$type);
		$saleinfo                                        =$this->get_build_map('sale_info');
		$basin_info_map                                  =$this->get_build_map('basin_info');
		$build_info                                      =$this->get_build_map('build_info');
		$property_info                                   =$this->get_build_map('property_info');
		$rent_info                                       =$this->get_build_map('rent_info');
		$page_info                                       =$this->get_build_map('page_info');

		foreach ($rent_info as $key5=>$item){
			$basic_info['rent_info'][$key5]['key']  =$item['title'];
			$basic_info['rent_info'][$key5]['value']=$project[$item['key']] ? $this->get_dict($project[$item['key']]).$item['d'] : '';
		}
		foreach ($saleinfo as $key1=>$item){
			$basic_info['sale_info'][$key1]['key']  =$item['title'];
			$basic_info['sale_info'][$key1]['value']=$build[$item['key']] ? $build[$item['key']].$item['d'] : '';
		}
		foreach ($page_info as $key1=>$item){

			$basic_info['page_info'][$key1]['key']  =$item['title'];
			$basic_info['page_info'][$key1]['value']=$build[$item['key']] ? $build[$item['key']].$item['d'] : '';
		}
		foreach ($basin_info_map as $key2=>$item){
			$basic_info['basin_info'][$key2]['key']=$item['title'];
			if (isset($item['map_text'])){
				$basic_info['basin_info'][$key2]['value']=$build[$item['key']] ? $item['map_text'][$build[$item['key']]].$item['d'] : '';
			}elseif($item['is_dict']===1){
				$basic_info['basin_info'][$key2]['value']=$build[$item['key']] ? $this->get_dict($build[$item['key']]).$item['d']  : '';
			}else{
				$basic_info['basin_info'][$key2]['value']=$build[$item['key']] ? $build[$item['key']].$item['d'] : '';
			}
		}
		foreach ($build_info as $key3=>$item){
			$basic_info['build_info'][$key3]['key']=$item['title'];
			if ($item['is_dict']===1){
				$basic_info['build_info'][$key3]['value']=$build[$item['key']] ? $this->get_dict($build[$item['key']]).$item['d'] : '';
			}else{
				$basic_info['build_info'][$key3]['value']=$build[$item['key']] ? $build[$item['key']].$item['d'] : '';
			}
		}
		foreach ($property_info as $key4=>$item){
			$basic_info['property_info'][$key4]['key']  =$item['title'];
			$basic_info['property_info'][$key4]['value']=$build[$item['key']] ? $build[$item['key']].$item['d'] : '';
		}
		$basic_info['build']['longitude']=$build['longitude'] ?: '';
		$basic_info['build']['latitude'] =$build['latitude'] ?: '';
		$basic_info['build']['address'] =$build['building_address'] ?: '';
		$day_price = $basic_info['price']>0?ceil($basic_info['price']/365/$avg_price['avg_area']):0;
		$basic_info['day_price'] = $day_price?:0;
		$basic_info['shop_group_pic']=$this->more_pic();
		$basic_info['shop_look_pic']=config('swb_shop.default_shop_look_pic');
		$basic_info['default_image']=config('swb_shop.default_image');
		return $basic_info;
	}

	/**
	 * @param $project_id
	 * @return Builder|\Hyperf\Database\Model\Model|object|null
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 获取项目
	 */
	protected function get_project($project_id)
	{
		return TProject::query()->where('id', $project_id)->first();
	}
	protected function project_tag($project_id)
	{
		$tag=Db::table('t_project_tag')->where('project_id', $project_id)->leftJoin('sys_data_dict', 'sys_data_dict.id', '=', 't_project_tag.tag_id')->leftJoin('sys_file', 'sys_file.id', '=', 'sys_data_dict.icon_id')->selectRaw('name as dictionaries_name,icon_id,access_path')->get();
		return $tag ?: [];
	}
	/**
	 * @Cacheable(prefix="shop_get_project_brand",value="_#{project_id}")
	 * @param $project_id
	 * @return array|\Hyperf\Utils\Collection
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 *
	 */
	protected function get_project_brand($project_id)
	{
		$info=Db::table('t_project_brand as a')->where('project_id', $project_id)->leftJoin('sys_file as b', 'a.brand_pic', '=', 'b.id')->select('b.access_path', 'a.brand_name', 'a.brand_pic')->take(8)->get();
		return $info ?: [];
	}
	/**
	 *
	 * @param $project_id
	 * @return array|\Hyperf\Utils\Collection
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 获取项目资讯
	 */
	protected function get_project_info($project_id)
	{
		$info=Db::table('t_project_info as a')
			->where('a.project_id',$project_id)
			->leftJoin('sys_file as b', 'a.icon', '=', 'b.id')
			->select('a.id', 'name', 'introduce', 'properties', 'b.access_path', 'a.create_time')->where('a.del_flag', 1)->take(3)->orderByDesc('id')->get();
		return $info ?: [];
	}
	protected function get_build_map(string $type): array
	{
		// 销售信息
		if ($type==='sale_info'){
			$info=[['title'=>'开发商', 'd'=>'', 'key'=>'developers', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'项目地址', 'd'=>'', 'key'=>'building_address', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'售楼地址', 'd'=>'', 'key'=>'sale_address', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'交房时间', 'd'=>'', 'key'=>'completion_date', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'预售证号', 'd'=>'', 'key'=>'booking_card_num', 'is_dict'=>0, 'is_hidden'=>1], ['title'=>'产权年限', 'd'=>'年', 'key'=>'property_right_year', 'is_dict'=>0, 'is_hidden'=>0],];
		}elseif ($type==='basin_info'){
			$info=[['title'=>'总套数', 'd'=>'套', 'key'=>'count_total_shop', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'建筑结构', 'key'=>'building_structure', 'is_dict'=>1, 'is_hidden'=>0,'d'=>''], ['title'=>'层高', 'd'=>'米', 'key'=>'floor_height', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'柱距', 'd'=>'米', 'key'=>'column_spaces', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'是否可分割', 'key'=>'partition_status', 'is_dict'=>0, 'is_hidden'=>0, 'map_text'=>[1=>'是', 2=>'否'],'d'=>''], ['title'=>'有无电梯', 'key'=>'has_elevator_status', 'is_dict'=>0, 'is_hidden'=>0, 'map_text'=>[1=>'有', 2=>'无'],'d'=>''], ['title'=>'电梯数量', 'd'=>'座', 'key'=>'count_elevators', 'is_dict'=>0, 'is_hidden'=>0],
			];
		}elseif ($type==='build_info'){
			$info=[['title'=>'装修状态', 'd'=>'', 'key'=>'decorate_status', 'is_dict'=>1, 'is_hidden'=>0], ['title'=>'车位数量', 'd'=>'个', 'key'=>'count_cars', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'供暖形式', 'd'=>'', 'key'=>'heating_type', 'is_dict'=>1, 'is_hidden'=>0],];
		}elseif ($type==='property_info'){
			$info=[['title'=>'物业名称', 'd'=>'', 'key'=>'property_name', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'物业标准收费', 'd'=>'元/㎡/月', 'key'=>'charge_property', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'水费标准', 'd'=>'元/吨', 'key'=>'charge_water', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'电费标准', 'd'=>'元/度', 'key'=>'charge_electricity', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'其他费用', 'key'=>'charge_other', 'is_dict'=>0, 'is_hidden'=>0],

			];
		}elseif ($type==='rent_info'){
			$info=[['title'=>'一次性付租周期', 'd'=>'', 'key'=>'pay_period', 'is_dict'=>1, 'is_hidden'=>0], ['title'=>'押金', 'd'=>'', 'key'=>'deposit_demand', 'is_dict'=>1, 'is_hidden'=>0], ['title'=>'免租期', 'd'=>'', 'key'=>'free_period', 'is_dict'=>1, 'is_hidden'=>0], ['title'=>'首次付款时间', 'd'=>'', 'key'=>'first_pay_time', 'is_dict'=>1, 'is_hidden'=>0],];
		}elseif ($type ==='page_info'){
			$info=[['title'=>'开发商', 'd'=>'', 'key'=>'developers', 'is_dict'=>0, 'is_hidden'=>0], ['title'=>'预售证号', 'd'=>'', 'key'=>'booking_card_num', 'is_dict'=>0, 'is_hidden'=>1],['title'=>'交房时间', 'd'=>'', 'key'=>'completion_date', 'is_dict'=>0, 'is_hidden'=>0],['title'=>'总套数', 'd'=>'套', 'key'=>'count_total_shop', 'is_dict'=>0, 'is_hidden'=>0]];
		}
		return $info;
	}
	/**
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 铺源介绍
	 * @param string $project_id
	 * @param $type
	 * @param int $page
	 * @param int $limit
	 * @return array
	 */
	protected function shop_list(string $project_id,$type,$page=1, $limit=5)
	{
		$hours_status = $type==2?[1,2,3,4,5]:[1,2,5,8,9];
		$count=TShop::query()
			->where('project_id', $project_id)
			->where('del_flag', 1)
			->whereIn('house_status',$hours_status)
			->when($type,function($query,$type){
				if($type==2)
				{
					$query->where('house_sale_rent',1)
						->where('del_flag',1);
				}
				if($type==3){
					$query->where('house_sale_rent',2)
						->where('del_flag',1);
				}
			})
			->whereIn('house_status',$hours_status)

			->count();
		if ($count){
			$info=TShop::query()->where('project_id', $project_id)
				->select('name', 'rental_price', 'sale_price', 'floor_area', 'id','project_id','house_status')
				->when($type,function($query,$type){
					if($type==2)
					{
						$query->where('house_sale_rent',1)
							->where('del_flag',1);
					}
					if($type==3){
						$query->where('house_sale_rent',2)
							->where('del_flag',1);
					}
				})
				->whereIn('house_status',$hours_status)
				->where('del_flag', 1)
				->orderBy('house_status')
				->forPage($page, $limit)->get()->toArray();
			foreach ($info as &$item2){
				if($type==2){
					$item2['total_price'] = number_format($item2['rental_price']*$item2['floor_area']/10000,2,'.','');
				}elseif ($type==3){
					$item2['total_price'] = number_format($item2['sale_price']*$item2['floor_area']/10000,2,'.','');
				}
			}
			$dict=make(SysDataDict::class)->get_dict_area();
			foreach ($dict as &$dic){
				$dic['room_info']=[];
				foreach ($info as &$item){
					$shop_file       =$this->get_shop_file($item['id']);
					$item['room_pic']=$shop_file[3101]??[];
					$item['outside_pic']=$shop_file[3102]??[];
					$use_value       =explode('-', $dic['use_value']);
					if (!empty($use_value[1])){
						if ($item['floor_area']>=$use_value[0]&&$item['floor_area']<$use_value[1]){
							array_push($dic['room_info'], $item);
						}
					}else{
						if ($item['floor_area']>$use_value[0]){
							array_push($dic['room_info'], $item);
						}
					}
				}
			}
		}
		return ['all'=>$info??[], 'area_group'=>$dict??[]];
	}

	/**
	 * @param $build_id
	 * @param $type
	 * @return array
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 楼盘标签
	 */
	protected function get_building_dictionary($build_id, $type): array
	{
		$info=TBuildingDictionary::query()->where('building_info_type', $type)->where('building_id', $build_id)->selectRaw('dict_name as dictionaries_name')->get();
		return $info ?: [];
	}
	protected function get_simple_rent_shop($id)
	{
		$shop=TShop::query()->select('name','id','rental_price as price','floor_area')->findOrFail($id);
		$logo                 =$this->get_logo($shop['id']);
		$shop['cover_pic'] = $logo?: config('swb_shop.default_url');
		$shop['total_price']  = ceil($shop['price']*$shop['floor_area']);
		return $shop;
	}
	protected function get_simple_project($id,$type)
	{
		$building_id = TProject::query()->where('id',$id)->value('building_id');
		$build    =$this->get_building($building_id,['building_name']);
		$logo                 =$this->get_logo($id);
		$avg_info = $this->get_project_price($id,$type);
		$data['price'] = $avg_info['avg_price'];
		$data['total_price'] = $avg_info['avg_total'];
		$data['cover_pic'] = $logo?:config('bxy.default_url');
		$data['name']      = $build['building_name'];
		return $data;
	}
	public function get_active_shop($id,$type)
	{
		if($type==1)
		{
			$data = $this->get_simple_rent_shop($id);
		}else{
			$data = $this->get_simple_project($id,$type);
		}
		return $data;
	}
	protected function get_shop_video($house_id,$file_type)
	{
		return Db::table('t_professional_work_file as tw')
			->leftJoin('sys_file as sf', 'sf.id', '=', 'tw.file_id')
			->where('professional_work_id', $house_id)
			->where('file_type', $file_type)
			->value('access_path');

	}
	protected function get_shop_all_video($house_id,$type)
	{
		$video_ids = $type==1?[3104,3105]:[2109,2110];
		$daka = $this->get_shop_video($house_id,$video_ids[0]);
		$people = $this->get_shop_video($house_id,$video_ids[1]);
		$arr['daka']['video_pic'] = $daka?$daka.'?x-oss-process=video/snapshot,t_7000,f_jpg,m_fast':'';
		$arr['people']['video_pic'] = $people?$people.'?x-oss-process=video/snapshot,t_7000,f_jpg,m_fast':'';
		return $arr;

	}
	/**
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 获取商铺报告
	 */
	protected function get_shop_report($id,$type)
	{
		$info = TShopReport::query()->where('business_id',$id)
			->select('report_name','report_title as title','report_describe','report_cover','report_details')
			->where('business_type',$type)
			->where('del_flag',1)
			->where('is_putaway',1)
			->get()->toArray();
		if($info)
		{
			foreach ($info as &$item)
			{
				$item['cover_pic'] = Db::table('sys_file')->where('id',$item['report_cover'])->value('access_path');
				$item['image'] = Db::table('sys_file')->where('id',$item['report_details'])->value('access_path');
			}
		}
		return $info?:[];
	}
	/**
	 *
	 * @param $id
	 * @return mixed
	 * User : 码农先生
	 * Email: 807098383@qq.com
	 * Website: http://blog.zsboss888.com
	 * 获取大咖说铺
	 */
	public function getDakaVideo($id,$type)
	{
		$video_ids = $type==1?[3104,3105]:[2109,2110];
		$daka_video = $this->get_shop_video($id,$video_ids[0]);
		$people_video = $this->get_shop_video($id,$video_ids[1]);
		$basic_info['daka']['video_id']  =$daka_video;
		$basic_info['people']['video_id']=$people_video;
		return $basic_info;
	}
}